package classifier;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

import learner.PatternType;
import learner.hmm.HMMModel;

import com.google.gson.stream.JsonReader;

public class HMModelReader {
	
	public HMModelReader() {
	}
	
	public List<HMMModel> giveModels(){
		List<HMMModel> models = new ArrayList<HMMModel>();
		for (PatternType patternType : PatternType.values()) {
			HMMModel model = readModel("models\\hmmmodel" + (patternType.ordinal() + 1) + ".json");
			models.add(model);
		}
		return models;
	}
	
	public HMMModel readModel(String fileName) {
		ObjectInputStream in;
		try {
			in = new ObjectInputStream(new FileInputStream(fileName));
			HMMModel model = (HMMModel)in.readObject();
			in.close();
			return model;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
			
		}
		catch (ClassNotFoundException e) {
			e.printStackTrace();
			return null;
		}
//		return gson.fromJson(reader, HMMModel.class);
	}

}

